package com.nuc.zyt.day02.Proxy;

import com.nuc.zyt.day02.Proxy.DynamicProxy.DynamicProxy;
import com.nuc.zyt.day02.Proxy.staticProxy.StaticProxy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName App
 * @Description TODO
 * @Author 耀酱
 * @Date 2023/5/15 11:08
 * @Version 1.0
 */

public class App {
    public static void main(String[] args) {
        try{
            Person person = new Person();

            // 现在需要在eat方法执行前后做一些记录操作，怎么办？？？

            // 1. 静态代理
            StaticProxy staticProxy = new StaticProxy(new Person());
            staticProxy.eat();

            System.out.println("---------------分割________________________");

            // 2. 动态代理
            Eat proxy =(Eat) DynamicProxy.getProxy(staticProxy,DynamicProxy.getHandle(person));
            proxy.eat();
            // getHandle(student1) 这里的对象决定代理的内容
            Student student1 = new Student();
            Eat student = (Eat) DynamicProxy.getProxy(student1,DynamicProxy.getHandle(student1));
            student.eat();


        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }
    }


}
